package net.huashitong.ssydt.provider.task.service;


import net.huashitong.ssydt.base.dao.LongMapper;
import net.huashitong.ssydt.base.service.AbstractLongService;
import net.huashitong.ssydt.provider.task.mapper.SsTaskMyMedalMapper;
import net.huashitong.ssydt.task.entity.SsTaskMyMedal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2018.01.19
 */
@Service
@Transactional
public class SsTaskMyMedalServiceImpl extends AbstractLongService<SsTaskMyMedal> implements SsTaskMyMedalService {

    private SsTaskMyMedalMapper mapper;

    @Autowired
    public SsTaskMyMedalServiceImpl(SsTaskMyMedalMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    protected LongMapper<SsTaskMyMedal> getLongMapper() {
        return this.mapper;
    }

    @Override
    public SsTaskMyMedal getAutoCreateByUserId(String userId) {
        SsTaskMyMedal ssTaskMyMedal = this.getByUserId(userId);
        if (ssTaskMyMedal == null) {
            ssTaskMyMedal = new SsTaskMyMedal();
            ssTaskMyMedal.setUserId(userId);
            ssTaskMyMedal.setMedalNumber(0);
            ssTaskMyMedal.setAddScore(BigDecimal.valueOf(0));
            this.insert(ssTaskMyMedal);
        }
        return ssTaskMyMedal;
    }

    @Override
    public SsTaskMyMedal getByUserId(String userId) {
        return this.mapper.getByUserId(userId);
    }


}
